package com.hanlin.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hanlin.backend.common.entity.HlAuthorityUser;
import com.hanlin.backend.mapper.HlAuthorityUserMapper;
import com.hanlin.backend.service.HlAuthorityUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hl.yuan
 * @since 2021-03-06
 */
@Service
@Slf4j
public class HlAuthorityUserServiceImpl extends ServiceImpl<HlAuthorityUserMapper, HlAuthorityUser> implements HlAuthorityUserService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeAuthority(Integer userId, Integer roleId) {
        if (userId==null && roleId==null) {
            log.error("用户ID和角色ID都为空不进行删除菜单权限数据");
            return;
        }

        UpdateWrapper wrapper = new UpdateWrapper();
        if (userId!=null) {
            wrapper.eq("user_id",userId);
        }
        if (roleId!=null) {
            wrapper.eq("user_id",userId);
        }
        remove(wrapper);

    }
}
